
package com.jml.mayi.consumer;

import com.rabbitmq.client.Channel;
import java.util.Map;
import org.springframework.amqp.core.Message;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.amqp.support.AmqpHeaders;
import org.springframework.messaging.handler.annotation.Headers;
import org.springframework.stereotype.Component;

@Component
public class FanoutEamilConsumer手动签收 {

	@RabbitListener(queues = "fanout_eamil_queue_id_ack")
	public void process(Message message, @Headers Map<String, Object> headers, Channel channel) throws Exception {
		//得到全局ID
		String messageId = message.getMessageProperties().getMessageId();
		//得到消息
		String msg = new String(message.getBody(), "UTF-8");
		System.out.println("邮件消费者获取生产者消息msg:" + msg + ",消息id:" + messageId);
		// 手动ack
		Long deliveryTag = (Long) headers.get(AmqpHeaders.DELIVERY_TAG);
		// 手动签收
		channel.basicAck(deliveryTag, false);
	}
	// 默认是自动应答模式
}

